using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class ImportFromGroupPage : BasePage
	{
		private const string TAG = "ImportFromGroupPage";
		private const int cNPageArgCnt = 1;
		private bool mBUseList;
		private ListBox mListBoxGroups;
		internal Grid LayoutRoot;
		internal StackPanel panelContents;
		private bool _contentLoaded;
		public event MMStandardUIEvent mEventSelectedGroup;
		public ImportFromGroupPage()
		{
			this.InitializeComponent();
		}
		protected override void OnPageLoaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("ImportFromGroupPage", "Page_Loaded");
		}
		protected override void OnPageUnLoaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("ImportFromGroupPage", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("ImportFromGroupPage", "OnPageIn");
			if (object_0 != null && 1 == object_0.Length)
			{
				if (object_0[0].GetType() == typeof(MMStandardUIEvent))
				{
					this.mEventSelectedGroup += (object_0[0] as MMStandardUIEvent);
					this.initUI();
					return;
				}
			}
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("ImportFromGroupPage", "OnPageOut");
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("ImportFromGroupPage", "OnPageBack");
		}
		private void ctrl_ItemClick(object sender, object args)
		{
			if (this.mEventSelectedGroup != null)
			{
				this.mEventSelectedGroup(this, args);
			}
			base.GoBack();
		}
		private void initUI()
		{
			IList<Contact> list = Enumerable.ToList<Contact>(ContactsView.GetChatRoomList());
			ObservableCollection<Conversation> list2 = ServiceCenter.conversationMgr.getList();
			if (list2 != null)
			{
				using (IEnumerator<Conversation> enumerator = list2.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Conversation current = enumerator.get_Current();
						if (ContactMgr.getUserType(current.strUsrName) == ContactMgr.UserType.UserTypeChatRoom)
						{
							Contact contact = StorageMgr.contact.method_0(current.strUsrName);
							if (contact != null && !list.Contains(contact))
							{
								list.Add(contact);
							}
						}
					}
				}
			}
			if (list == null)
			{
				return;
			}
			if (list.get_Count() > 10)
			{
				this.mBUseList = true;
				this.mListBoxGroups = new ListBox();
				this.mListBoxGroups.set_Height(768.0);
				this.panelContents.get_Children().Add(this.mListBoxGroups);
				this.mListBoxGroups.set_ItemTemplate((DataTemplate)base.get_Resources().get_Item("listboxTemplate"));
				this.mListBoxGroups.set_ItemsSource(list);
				return;
			}
			this.addContacts(list);
		}
		private void addContacts(IList<Contact> group)
		{
			using (IEnumerator<Contact> enumerator = group.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Contact current = enumerator.get_Current();
					SnsGroupAbstract snsGroupAbstract = new SnsGroupAbstract();
					this.panelContents.get_Children().Add(snsGroupAbstract);
					snsGroupAbstract.ItemClick += new MMStandardUIEvent(this.ctrl_ItemClick);
					snsGroupAbstract.mGroupContact = current;
				}
			}
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		public static void GotoThisPage(MMStandardUIEvent mmstandardUIEvent_0)
		{
			object[] object_ = new object[]
			{
				mmstandardUIEvent_0
			};
			ToolFunction.GotoPageForUserControl("/Source/UI/Contact/ImportFromGroupPage.xaml", object_, false);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Contact/ImportFromGroupPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelContents = (StackPanel)base.FindName("panelContents");
		}
	}
}
